package com.ruoyi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.IdUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DriveInfo;
import com.ruoyi.system.service.IDriveInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约记录Controller
 * 
 * @author ruoyi
 * @date 2022-03-19
 */
@RestController
@RequestMapping("/system/info")
public class DriveInfoController extends BaseController
{
    @Autowired
    private IDriveInfoService driveInfoService;

    /**
     * 查询预约记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(DriveInfo driveInfo)
    {
        startPage();
        List<DriveInfo> list = driveInfoService.selectDriveInfoList(driveInfo);
        return getDataTable(list);
    }

    /**
     * 导出预约记录列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "预约记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DriveInfo driveInfo)
    {
        List<DriveInfo> list = driveInfoService.selectDriveInfoList(driveInfo);
        ExcelUtil<DriveInfo> util = new ExcelUtil<DriveInfo>(DriveInfo.class);
        util.exportExcel(response, list, "预约记录数据");
    }

    /**
     * 获取预约记录详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{driveId}")
    public AjaxResult getInfo(@PathVariable("driveId") String driveId)
    {
        return AjaxResult.success(driveInfoService.selectDriveInfoByDriveId(driveId));
    }

    /**
     * 新增预约记录
     */
    //@PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "预约记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DriveInfo driveInfo)
    {
        driveInfo.setDriveId(IdUtil.simpleUUID());
        return toAjax(driveInfoService.insertDriveInfo(driveInfo));
    }

    /**
     * 修改预约记录
     */
    //@PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "预约记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DriveInfo driveInfo)
    {
        return toAjax(driveInfoService.updateDriveInfo(driveInfo));
    }

    /**
     * 删除预约记录
     */
    //@PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "预约记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{driveIds}")
    public AjaxResult remove(@PathVariable String[] driveIds)
    {
        return toAjax(driveInfoService.deleteDriveInfoByDriveIds(driveIds));
    }
}
